package com.dxyxx.dialog;



import com.dxyxx.R;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class PhonePlayer {
	public static void makeCall(final Activity activity, final String number) {
		/*LayoutInflater inflater = activity.getLayoutInflater();
		AlertDialog.Builder builder = new AlertDialog.Builder(activity);
		View view = inflater.inflate(R.layout.common_alertdialog, null);
		builder.setView(view);
		final AlertDialog dialog = builder.show();*/
		final DKDialog dialog = new DKDialog(activity,R.style.MyDialog);
		dialog.setContentView(R.layout.common_alertdialog);
		
		dialog.show();
		TextView tv = (TextView) dialog.findViewById(R.id.tv_common_alerdialog_content);
		tv.setText("您确定要拨打该号码吗： "+number);
		/*
		 * 监听imgbtn关闭dialog
		 */
		ImageView customviewtvimgCancel = (ImageView) dialog.findViewById(R.id.customviewtvimgCancel);
		customviewtvimgCancel.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				dialog.dismiss();
			}
		});
		/*
		 * 监听btn 打电话
		 */
		Button buttonSure = (Button) dialog.findViewById(R.id.b_sure);
		buttonSure.setOnTouchListener(new ViewTouchListener(activity, buttonSure));
		buttonSure.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				dialog.dismiss();
				// 用intent启动拨打电话
				Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + number));
				activity.startActivity(intent);
			}
		});
		/*
		 * 监听取消
		 */
		Button buttonCancel = (Button) dialog.findViewById(R.id.b_cancel);
		buttonCancel.setOnTouchListener(new ViewTouchListener(activity, buttonCancel));
		buttonCancel.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				dialog.dismiss();
			}
		});
	}
}
